import { _decorator, Component, Node, Button, Widget } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('BaseWxPage')
export abstract class BaseWxPage extends Component {
    @property(Button)
    public ClickNode: Button = undefined;

    public _index: string;
    private _closeCB: Function;

    public Show(index: string, closeCB: Function) {
        this._index = index;
        this._closeCB = closeCB;
        this.SetButton();
        this.node.active = true
        this.OnShow();
        // wxsdk.GetAdById(`${this.node.name}_${this._index}_Show`);
    }

    public Hide() {
        this.OnHide();
        // wxsdk.GetAdById(`${this.node.name}_${this._index}_Hide`);
        this.node.active = false
        this._closeCB ? this._closeCB() : null;
    }

    public abstract OnShow();

    public abstract OnBtnClick();

    public abstract OnHide();

    protected SetButton() {
        // this.ClickNode.node.active = true
        // var HorStr = wxsdk.GetConfigById(`${this.node.name}_${this._index}_Hor`);
        // var VerStr = wxsdk.GetConfigById(`${this.node.name}_${this._index}_Ver`);
        // var HorValueStr = wxsdk.GetConfigById(`${this.node.name}_${this._index}_HorValue`);
        // var VerValueStr = wxsdk.GetConfigById(`${this.node.name}_${this._index}_VerValue`);
        // var widget = this.ClickNode.getComponent(Widget);
        // var Hor = Number.parseFloat(HorStr);
        // var Ver = Number.parseFloat(VerStr);
        // var HorValue = Number.parseFloat(HorValueStr);
        // var VerValue = Number.parseFloat(VerValueStr);
        // widget.isAlignLeft = Hor == -1;
        // widget.isAlignRight = Hor == 1;
        // widget.isAlignHorizontalCenter = Hor == 0;

        // widget.isAlignTop = Ver == -1;
        // widget.isAlignBottom = Ver == 1;
        // widget.isAlignVerticalCenter = Ver == 0;

        // widget.left = Hor == -1 ? HorValue : 0;
        // widget.right = Hor == 1 ? HorValue : 0;
        // widget.horizontalCenter = Hor == 0 ? HorValue : 0;

        // widget.top = Ver == -1 ? VerValue : 0;
        // widget.bottom = Ver == 1 ? VerValue : 0;
        // widget.verticalCenter = Ver == 0 ? VerValue : 0;
    }

}

